package com.hangxiang.approval.controller;


import javax.servlet.http.HttpServletRequest;

import com.hangxiang.approval.enums.ResultStatusEnum;
import com.hangxiang.approval.exception.MyException;
import com.hangxiang.approval.utils.OSSClientUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("UpFileController")
@Api(tags = "文件上传")
public class UpFileController {

	@Autowired
	private OSSClientUtil ossClient;

	@PostMapping("headImgUpload")
	@ResponseBody
	public String headImgUpload(HttpServletRequest request,MultipartFile file) {
		if (file == null || file.getSize() <= 0) {
			throw new MyException(ResultStatusEnum.UPLOADFILE);
		}
		String name = ossClient.uploadImg2Oss(file);
		String imgUrl = ossClient.getImgUrl(name);
		return imgUrl;
	}
	
}
